package bz.yfw.example.s3blazeds.part2.helper
{
	import bz.yfw.example.s3blazeds.part2.model.ro.EmpRemotoObject;
	import bz.yfw.example.s3blazeds.part2.model.view.EmpViewModel;
	import bz.yfw.example.s3blazeds.part2.view.EmpEditView;
	
	import mx.utils.object_proxy;
	
	import org.seasar.akabana.yui.framework.ns.viewpart;
	
	import spark.components.RadioButton;
	import spark.components.RadioButtonGroup;
	import spark.components.TextInput;
	import spark.components.supportClasses.ViewReturnObject;
	
	use namespace viewpart;
	
	/**
	 * 社員編集画面Helper
	 * @author tokufxug http://twitter.com/tokufxug
	 */
	public class EmpEditInitHelper
	{
		public var view:EmpEditView;
		
		viewpart var txtinptName:TextInput;
		viewpart var rdbgrpSex:RadioButtonGroup;
		viewpart var rdbtnMan:RadioButton;
		viewpart var rdbtnWoman:RadioButton;
		
		viewpart var txtinptYear:TextInput;
		viewpart var txtinptMonth:TextInput;
		viewpart var txtinptDate:TextInput;
		
		public function get empViewModel():EmpViewModel {
			var retObj:ViewReturnObject = view.navigator.poppedViewReturnedObject;
			
			if (retObj && retObj.object) {
				return retObj.object as EmpViewModel;
			}
			return null;
		}
		
		public function reflectEmpModel():void {
			var vm:EmpViewModel = empViewModel;
			if (!vm) {
				return;
			}
			txtinptName.text = vm.name;
			txtinptYear.text = vm.year;
			txtinptMonth.text = vm.month;
			txtinptDate.text = vm.date;
			rdbgrpSex.selectedValue = vm.sex;
			
			view.viewModel = vm;
		}
		
		public function initSex():void {
			rdbtnMan.group = rdbtnWoman.group = rdbgrpSex;
		}
	}
}